import { DialogForm } from 'custom/index'
import { addCustomerAndShop, editCustomerAndShop, getFpListByCustomerId } from '../api'
import ZxjlSelect from '../components/ZxjlSelect.vue'
import GlkhSelect from '../components/GlkhSelect.vue'
import ShopList from '../components/ShopList.vue'
import FpList from '../components/FpList.vue'
import XfzySelect from '../components/XfzySelect.vue'

const addDialog = new DialogForm('DialogForm')
const editDialog = new DialogForm('DialogForm')
const fpDialog = new DialogForm('DialogForm')

addDialog
    .title('添加客户')
    .width('80%')
    .getApi(async () => {
        return {
            khhzztVal: '正在合作',
            khhzztName: '正在合作'
        };
    })
    .postApi(addCustomerAndShop)
    .useGroup('客户信息')
    .useCustomItem(ZxjlSelect, 'zxid').span(6).label('咨询记录').end() // 咨询记录
    .useItem('khmc').label('客户名称').required().span(6).end()
    .useDictSelect('tklxVal', 'marketType').label('拓客类型').setProp('widthLabel', 'tklxName').span(6).end()
    .useDictSelect('tkqdVal', 'expandType').label('拓客渠道').setProp('widthLabel', 'tkqdName').required().span(6).end()
    .useDatePicker('khschzsj').label('客户首次合作时间').span(6).end()
    .useCustomItem(GlkhSelect, 'glkhId').span(6).label('关联客户').end()
    .useDictSelect('glgxVal', 'glgx').label('关联关系').setProp('widthLabel', 'glgxName').span(6).end()
    .useDictSelect('khhzztVal', 'hzzt').label('客户合作状态').setProp('widthLabel', 'khhzztName').span(6).end()
    .useCustomItem(XfzySelect, 'xfzyUserId').label('续费专员').span(6).end()
    .useDictSelect('xfjdVal', 'xfjd').label('续费节点').required().setProp('widthLabel', 'xfjdName').span(6).end()
    .useItem2('khxxbz').label('客户信息备注').span(24).end()
    .useCustomItem(ShopList, 'customerShopList').label('').setDefault([]).end()

editDialog
    .title('编辑客户')
    .width('80%')
    .getApi(async (_, row) => {
        return row;
    })
    .postApi(editCustomerAndShop)
    .useGroup('客户信息')
    .useCustomItem(ZxjlSelect, 'zxid').span(6).label('咨询记录').end() // 咨询记录
    .useItem('khmc').label('客户名称').required().span(6).end()
    .useDictSelect('tklxVal', 'marketType').label('拓客类型').setProp('widthLabel', 'tklxName').span(6).end()
    .useDictSelect('tkqdVal', 'expandType').label('拓客渠道').setProp('widthLabel', 'tkqdName').required().span(6).end()
    .useDatePicker('khschzsj').label('客户首次合作时间').span(6).end()
    .useCustomItem(GlkhSelect, 'glkhId').span(6).label('关联客户').end()
    .useDictSelect('glgxVal', 'glgx').label('关联关系').setProp('widthLabel', 'glgxName').span(6).end()
    .useDictSelect('khhzztVal', 'hzzt').label('客户合作状态').setProp('widthLabel', 'khhzztName').span(6).end()
    .useCustomItem(XfzySelect, 'xfzyUserId').label('续费专员').span(6).end()
    .useDictSelect('xfjdVal', 'xfjd').label('续费节点').required().setProp('widthLabel', 'xfjdName').span(6).end()
    .useItem2('khxxbz').label('客户信息备注').span(24).end()
    .useCustomItem(ShopList, 'customerShopList').label('').setDefault([]).end()

fpDialog
    .title('发票管理')
    .width('80%')
    .getApi(async (_, row) => {
        // 根据客户id查询发票集合
        const fpList = await getFpListByCustomerId({ customerId: row.customerId });
        row.fpList = fpList;
        return row;
    })
    .useGroup('客户信息')
    .useItem('khmc').label('客户名称').setProp('disabled', true).span(6).end()
    .useCustomItem(FpList, 'fpList').label('').setDefault([]).end()

export { addDialog, editDialog, fpDialog }